#include "SecondBoundary.h"
#include <cmath>

SecondBoundary::SecondBoundary(void)
{
}
SecondBoundary::SecondBoundary( Element *source, int p1WhichInTriangle, int p2WhichInTriangle, double val )
{
	parentElement = source;
	this->val = val;

	switch (p1WhichInTriangle)
	{
	case 1:
		v[0] = parentElement->a;
		indexedPointLocation[0] = 1;
		break;

	case 2:
		v[0] = parentElement->b;
		indexedPointLocation[0] = 2;
		break;

	case 3:
		v[0] = parentElement->c;
		indexedPointLocation[0] = 3;
		break;
	}

	switch (p2WhichInTriangle)
	{
	case 1:
		v[1] = parentElement->a;
		indexedPointLocation[1] = 1;
		break;

	case 2:
		v[1] = parentElement->b;
		indexedPointLocation[1] = 2;
		break;

	case 3:
		v[1] = parentElement->c;
		indexedPointLocation[1] = 3;
		break;
	}

	if ((v[1]->getX() == v[0]->getX())&&(v[1]->getY() != v[0]->getY()))
	{
		location = -1;
	}
	else if ((v[1]->getX() != v[0]->getX())&&(v[1]->getY() == v[0]->getY()))
	{
		location = 1;
	}
	else
	{
		location = 0;
	}

	triangleField =	abs(((parentElement->b->getX() - parentElement->a->getX()) * (parentElement->c->getY() - parentElement->a->getX())) -
						((parentElement->c->getX() - parentElement->a->getX()) * (parentElement->b->getY() - parentElement->a->getY())))/2;
}
SecondBoundary::~SecondBoundary(void)
{
}
mPoint SecondBoundary::getPointA()
{
	return *v[0];
}
mPoint SecondBoundary::getPointB()
{
	return *v[1];
}
double SecondBoundary::getVal()
{
	return val;
}
int SecondBoundary::getLocation()
{
	return location;
}
double SecondBoundary::getTriangleField()
{
	return triangleField;
}
int* SecondBoundary::getIndexPointTable()
{
	return indexedPointLocation;
}
Element SecondBoundary::getParentElement()
{
	return *parentElement;
}
mPoint** SecondBoundary::getPoints()
{
	return v;
}
int SecondBoundary::UniqueIndex()
{
	return uniqueIndex;
}
void SecondBoundary::UniqueIndex(int val)
{
	uniqueIndex = val;
}